package com.date.demo03;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class Test {
    public static void main(String[] args) {
        System.out.println("ZonedDateTime");
        /**
         * ZonedDateTime 带时区返回
         */
        ZonedDateTime now = ZonedDateTime.now();
        System.out.println(now); // 2021-12-23T18:04:34.279+08:00[Asia/Shanghai]
        // 用指定时区获取当前时间
        ZonedDateTime zny = ZonedDateTime.now(ZoneId.of("America/New_York"));
        System.out.println(zny); // 2021-12-23T05:04:34.281-05:00[America/New_York]

        // LocalDateTime附加一个ZoneId，就可以变成ZonedDateTime：
        LocalDateTime ldt = LocalDateTime.of(2019, 9, 15, 15, 16, 17);
        ZonedDateTime zbj = ldt.atZone(ZoneId.systemDefault());
        ZonedDateTime ny = ldt.atZone(ZoneId.of("America/New_York"));
        System.out.println(zbj);
        System.out.println(ny);
    }
}
